﻿namespace ElisVK.Controls
{
    using System.Reflection;
    using System.Windows.Controls;

    public class DoubleToPercentSlider : Slider
    {
        #region Field

        private ToolTip _autoToolTip;

        #endregion

        #region Properties

        private ToolTip AutoToolTip
        {
            get
            {
                if (_autoToolTip == null)
                {
                    FieldInfo field = typeof(Slider).GetField(
                        "_autoToolTip", BindingFlags.NonPublic | BindingFlags.Instance);
                    _autoToolTip = field.GetValue(this) as ToolTip;
                }

                return _autoToolTip;
            }
        }

        #endregion

        #region Implementation

        protected override void OnThumbDragStarted(System.Windows.Controls.Primitives.DragStartedEventArgs e)
        {
            base.OnThumbDragStarted(e);
            AutoToolTip.Content = string.Format("{0}%", Value * 100);
        }

        protected override void OnThumbDragDelta(System.Windows.Controls.Primitives.DragDeltaEventArgs e)
        {
            base.OnThumbDragDelta(e);
            AutoToolTip.Content = string.Format("{0}%", Value * 100);
        }

        #endregion
    }
}
